#!/usr/bin/env node

// mac 执行 chmod 755 文件读写权限

const inquirer = require('inquirer');
const path = require('path');
const fs = require('fs');
const ejs = require('ejs');

inquirer.prompt({
    type: 'input',
    name: 'name',
    message: '项目名称'
  })
  .then(answer => {
    const templa = path.join(__dirname, 'template');

    const destDir = process.cwd();

    fs.readdir(templa, (err, files) => {
      if (err) {
        throw err
      };

      files.forEach(file => {
        console.log(file)
        ejs.renderFile(path.join(templa, file), answer, (err, result) => {
          if (err) throw err;

          fs.writeFileSync(path.join(destDir, file), result);
        })
      })
    })
  })